package com.maila.xiaoaoschool.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.text.InputType;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.VolleyError;
import com.maila.xiaoaoschool.R;
import com.maila.xiaoaoschool.api.LoginApi;
import com.maila.xiaoaoschool.net.VolleyInterface;
import com.zhy.autolayout.AutoRelativeLayout;

import org.json.JSONException;
import org.json.JSONObject;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;



/**
 * 修改个人信息
 * Created by mark on 2017/12/18.
 */

public class EditPersonalInfoActivity extends AppCompatActivity {
    @BindView(R.id.white_return_iv)
    AutoRelativeLayout whiteReturnIv;
    @BindView(R.id.tv_title_name)
    TextView tvTitleName;
    @BindView(R.id.save_information_tv)
    TextView saveInformationTv;
    @BindView(R.id.edit_personal_info)
    EditText editPersonalInfo;
    int type ;
    private String phone="";
    private String name="";
    private String age="";
    String hint;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_edit_personal_info);
        ButterKnife.bind(this);
        type=getIntent().getIntExtra("OPT",-1);
        switch (type){
            case 1:
               hint="请填写您的昵称";
                editPersonalInfo.setInputType(InputType.TYPE_CLASS_TEXT);
                break;
            case 2:
                hint="请填写您的手机号";
                editPersonalInfo.setInputType(InputType.TYPE_CLASS_PHONE);
                break;
            case 3:
                editPersonalInfo.setInputType(InputType.TYPE_CLASS_NUMBER);
                hint="请填写您的年龄";
                break;
        }
        editPersonalInfo.setHint(hint);
    }

    @OnClick({R.id.white_return_iv, R.id.save_information_tv})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.white_return_iv:
                finish();
                break;
            case R.id.save_information_tv:
                new LoginApi(this, new VolleyInterface() {
                    @Override
                    public void onSuccess(String result) {
                        try {
                            JSONObject jsonObject=new JSONObject(result);
                            if(jsonObject.optInt("result")==1){
                                Toast.makeText(EditPersonalInfoActivity.this,"修改成功",Toast.LENGTH_SHORT).show();
                                finish();
                            }else {
                                Toast.makeText(EditPersonalInfoActivity.this,"修改失败",Toast.LENGTH_SHORT).show();
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                    }

                    @Override
                    public void onError(VolleyError error) {

                    }
                }).set_user_info("",name,"",age,phone,"");
                break;
        }
    }
}
